﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for NguoiDungDAO
/// </summary>
public class NguoiDungDAO
{
    DataProvider provider;
	public NguoiDungDAO()
	{		
        provider = new DataProvider();
	}

    public NguoiDung DangNhap(string tenDangNhap, string matKhau)
    {
        NguoiDung dto = new NguoiDung();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_DangNhap", provider.Conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection.Open();
            cmd.Parameters.Add("@TenDangNhap", SqlDbType.VarChar).Value = tenDangNhap;
            cmd.Parameters.Add("@MatKhau", SqlDbType.VarChar).Value = matKhau;
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = cmd;
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            cmd.Connection.Close();

            if (ds.Tables[0].Rows.Count > 0)
            {
                dto.IDNguoiDung = Convert.ToInt32(ds.Tables[0].Rows[0]["IDNguoiDung"].ToString());
                dto.TenHienThi = ds.Tables[0].Rows[0]["TenHienThi"].ToString();
                dto.PhanQuyen = int.Parse(ds.Tables[0].Rows[0]["PhanQuyen"].ToString());
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            provider.Conn.Close();
        }
        return dto;
    }
}